<template>
    <div>
        <el-container class="form-container">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>Demo</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="submitForm">保存</el-button>
                </div>
                <div >
                   <el-form  :rules="rules"  ref="form"   :model="form" size="small" label-width="120px">
                        <el-row>
                          <el-col :span="12">
                            <el-form-item  label="参数名称"  prop="fdName">
                                <el-input class="input" v-model="form.fdName"  ></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="12">
                            <el-form-item  label="参数值" prop="fdValue">
                                <el-input class="input" v-model="form.fdValue" ></el-input>
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row>
                        <el-col :span="12">
                            <el-form-item  label="是否系统内置" prop="fdIsSystem">
                                <el-switch v-model="form.fdIsSystem" />
                            </el-form-item>
                        </el-col>
                        
                        </el-row>
                        <el-row>
                          <el-col :span="24">
                            <el-form-item  label="备注"  prop="fdRemark" >
                                <el-input type="textarea" class="input" :rows="4" v-model="form.fdRemark" style="width:95%" ></el-input>
                            </el-form-item>
                          </el-col>
                        </el-row>
                   </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import dateUtils from '@/utils/dateUtils';
import formUtils from '@/utils/formUtils';
export default {
    name: "SysConfigMainAdd",
    components: {
        
    },
    data() {
        return {
            form: {
                fdId:'',
                fdCreateTime:'',
                fdIsSystem:true,
                fdName:'',
                fdValue:'',
                fdRemark:''
            },
            rules:{
                fdName :[{required: true, message: '请输入参数名称', trigger: 'blur'}],
                fdValue :[{required: true, message: '请输入参数值', trigger: 'blur'}]
	        }
        }
    },
    created() {
        this.initParam();
    },
    methods: {
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    let forms = formUtils.convertToModel(this.form);
                    this.$put('/api/sys/config/sys_config_main',forms).then((res) => {
                        if(res.status==1){
                            this.$message({
                                message: res.message,
                                type: 'success',
                                onClose:()=>{
                                    this.$common.closeTag();
                                }
                            });
                        }else{
                            this.$message.error(res.message);
                        }
                    });

                }
            });
        },
        initParam() {
            let fdId = this.$route.query.id;
            if(formUtils.isNotEmpty(fdId)){
                this.fullscreenLoading = true;
                this.$fetch('/api/sys/config/sys_config_main',{
                    id:fdId
                }).then((res) => {
                    console.log(res.data);
                    formUtils.convertToForm(res.data,this.form);
                    console.log(this.form);
                    this.fullscreenLoading = false;
                });
            }
        }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>